import {CommonAction} from "../actions/CommonAction";
import Immutable from 'immutable';

import adminUser from '../state/system/adminUser'

import vipList from '../state/system/vipList'
import vipOrderList from '../state/system/vipOrderList'

const initialState = {
    adminUser: Immutable.fromJS(adminUser),
    vipList: Immutable.fromJS(vipList),
    vipOrderList: Immutable.fromJS(vipOrderList),
};

export default function reducer(state = initialState, action) {
    switch (action.type) {
        case CommonAction.TEMP_SET_KEY:
            let {k, v, m} = action.payload;
            let key = k.shift();

            if (!key) { // 清空整个state
                return Object.assign({}, state, initialState);
            }

            let nextState = {};
            if (!k.length && !v) { // 清空 单个state
                nextState[key] = initialState[key];

                return Object.assign({}, state, nextState);
            } else { // Immutable 操作
                nextState[key] = state[key][m](k, v);
                return Object.assign({}, state, nextState);
            }
        default:
            return state;
    }
}